# 用户注册
def register():
    username = input("输入用户名：")
    password = input("输入密码：")
    re_password = input("请再次输入密码：")

    if password == re_password:
        # 保存信息
        with open(r"D:\原文件夹\users.txt","a") as w_stream:
            w_stream.write(f"{username} {password}\n")
        print("用户注册成功！")
    else:
        print("密码不一致！")

# 用户登录
def log():
    username = input("输入用户名：")
    password = input("输入密码：")

    if username and password:
        with open(r"D:\原文件夹\users.txt") as r_stream:
            while True:
                user = r_stream.readline()
                if not user:
                    print("用户名或者密码输入有误！")
                    break

                input_user = f"{username} {password}\n"

                if user == input_user:
                    print("用户登录成功！")
                    break

# 图书展示
def show_books():
    print("------图书馆里面的图书有：------")
    with open(r"D:\原文件夹\books.txt","r") as r_stream:
        books = r_stream.readlines()
        for book in books:
            print(book,end="")     # 因为读取的内容中有\n,所以取消print中自带的末尾换行

# 调用函数
register()
log()
show_books()